package model;

import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.Shape;
import java.awt.geom.Rectangle2D;

public class RandomNPC extends NPC
{
	private static final double MAX_DEVIATION = 200.0;
	private double dOriginX, dOriginY;
	private double dCurrentX, dCurrentY;
	private double dWidth, dHeight;
	
	private boolean increasingX;
	
	public RandomNPC(int dXPosition, int dYPosition, int dWidth, int dHeight)
	{
		this.dOriginX = this.dCurrentX = dXPosition;
		this.dOriginY = this.dCurrentY = dYPosition;
		this.dWidth = dWidth;
		this.dHeight = dHeight;
		
		increasingX = true;
	}
	
	@Override
	public void update() 
	{
		if(dCurrentX < (dOriginX + MAX_DEVIATION) && increasingX)
		{
			dCurrentX++;
		}
		else if(dCurrentX >= (dOriginX + MAX_DEVIATION))
		{
			increasingX = false;
			dCurrentX--;
		}
		else if(dCurrentX > dOriginX && !increasingX)
		{
			dCurrentX--;
		}
		else if(dCurrentX <= dOriginX && !increasingX)
		{
			increasingX = true;
			dCurrentX++;
		}
	}

	@Override
	public void render(Graphics2D g2d) 
	{
		//DEBUGGING CHECKS
		if(Settings.DebugMode)
		{
			g2d.setColor(Color.WHITE);
			g2d.drawString("X: " + (int) dCurrentX + " Y: " + (int) dCurrentY,(int) dCurrentX,(int) dCurrentY);
		}
		if(Settings.DrawHitboxes)
		{
			g2d.setColor(Color.WHITE);
			g2d.draw(getHitBox());
		}
		
		//ACTUAL RENDERING
		g2d.setColor(Color.BLUE);
		g2d.fillRect((int) dCurrentX,(int) dCurrentY,(int) dWidth,(int) dHeight);
	}

	@Override
	public Shape getHitBox() 
	{
		return new Rectangle2D.Double(dCurrentX - (dWidth / 5), dCurrentY - (dHeight / 5), dWidth + ((dWidth / 5) * 2), dHeight + ((dHeight / 5) * 2));
	}
}
